package com.softstao.guoyu.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.softstao.guoyu.R;
import com.softstao.guoyu.model.agent.Product;
import com.softstao.guoyu.ui.baseAdapter.RecycleViewBaseAdapter;
import com.softstao.guoyu.ui.baseAdapter.RecycleViewHolder;

import java.util.List;

/**
 * Created by vaikus on 2017/7/3.
 */

public class ProductAdapter extends RecycleViewBaseAdapter<Product> {
    public ProductAdapter(List<Product> datas) {
        super(datas, R.layout.layout_order_goods_item);
    }

    @Override
    public void convert(RecycleViewHolder holder, Product product) {
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        holder.itemView.setLayoutParams(layoutParams);
        if (product.getImg() != null && !product.getImg().equals("")) {
            Glide.with(mContext).load(product.getImg()).into((ImageView) holder.getView(R.id.img));
        } else {
            ((ImageView) holder.getView(R.id.img)).setImageResource(R.mipmap.default_im);
        }
        holder.setText(R.id.name, product.getName())
                .setText(R.id.num, "x" + product.getCount() + "台");
        holder.getView(R.id.price).setVisibility(View.GONE);
    }
}
